package com.jydd.singlekotlinmvvm.comm.feature.search

import android.os.Bundle
import androidx.navigation.fragment.findNavController
import com.jydd.singlekotlinmvvm.R
import com.jydd.singlekotlinmvvm.comm.base.BaseFragment
import com.jydd.singlekotlinmvvm.comm.feature.search.controller.SearchController
import com.jydd.singlekotlinmvvm.comm.helpers.LoadMoreRecyclerviewScrollListener
import kotlinx.android.synthetic.main.fragment_search.*
import org.koin.android.scope.currentScope
import org.koin.android.viewmodel.ext.android.sharedViewModel
import org.koin.android.viewmodel.ext.android.viewModel

/**
 * created by 韦敏敏p
 * on 2020/1/21
 */
class SearchFragment : BaseFragment() {
    override fun layout(): Int = R.layout.fragment_search
    private val searchController by lazy {
        SearchController{
            val bundle = Bundle().apply {
                putString("URL", it.svnUrl)
            }
            findNavController().navigate(R.id.action_search_to_detail, bundle)
        }.apply {
            addModelBuildListener {
                if (!isLoadMoreAction) rvSearchResult.scrollToPosition(0)
            }
        }
    }
    private var isLoadMoreAction = false
    private lateinit var loadMoreListener : LoadMoreRecyclerviewScrollListener
    private val searchViewMore by currentScope.viewModel(this, SearchViewModel::class)
    private val launcherViewModel by sharedViewModel(Lau)
}